﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ADC.DAL;
using ADC.BL;
using ADC.Utilites;

namespace ADC.Web.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        log4net.ILog logger = log4net.LogManager.GetLogger("Login");
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Login" + Common.PAGE_TITLE;
            txtUsername.Focus();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            try
            {
                var userInfo = new User { UserName = txtUsername.Text.Trim(), Password = txtPassword.Text.Trim() };

                var user = UserFactory.CheckLogin(userInfo);
                if (user != null && user.UserID > 0)
                {
                    Session["UserInfo"] = user;
                    Response.Redirect("Default.aspx", false);
                }
                else
                {
                    // Show error message
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('The username or password is wrong');", true);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsEnableDebugMode) throw;
            }
        }
    }
}